package b4.view.component
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import org.aswing.*;
	import org.aswing.geom.IntDimension;
	import org.smartbird.Message;

	public class ChatDialog extends Sprite
	{
		public var inputField:JTextField;
		public var sendButton:JButton;
		private var tabbedPane:JTabbedPane;
		private var textArea:JTextArea;
		private var wholePane :JPanel;
		private var textArea_1:JTextArea;
		private var selComb:JComboBox;
		private var inputPene:JPanel;

		public function ChatDialog()
		{
			super();
			var jwin:JWindow = new JWindow(this);	
			
			wholePane = new JPanel(new BoxLayout(BoxLayout.Y_AXIS));
			
			tabbedPane = new JTabbedPane();
			tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
			textArea = new JTextArea();
			textArea.setSizeWH(300, 260);
			var chatPane:JPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0, false));
			var scrollPane:JScrollPane = new JScrollPane(textArea);
			scrollPane.setPreferredSize(new IntDimension(260, 260));
			chatPane.append(scrollPane);
			
			tabbedPane.appendTab(chatPane, "世界");


			textArea_1 = new JTextArea();
			textArea_1.setSizeWH(300, 260);
			var chatPane_1:JPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0, false));
			var scrollPane_1:JScrollPane = new JScrollPane(textArea_1);
			scrollPane_1.setPreferredSize(new IntDimension(260, 260));
			chatPane_1.append(scrollPane_1);
			tabbedPane.appendTab(chatPane_1, "队伍");
	
			inputPene = new JPanel(new FlowLayout());			
			var listData :Array = ["工会", "队伍"] ;
			var model : VectorListModel = new VectorListModel(listData)
			selComb = new JComboBox(model);
			selComb.setPreferredWidth(50);
			selComb.setMaximumRowCount(3);
			selComb.setSelectedIndex(0);
			inputPene.append(selComb);
			
			inputField = new JTextField("请输入内容", 22);			
			inputPene.append(inputField);

			sendButton = new JButton("发送");
			inputPene.append(sendButton);
			
			wholePane.append(tabbedPane);
			wholePane.append(inputPene);
			jwin.setSizeWH(300, 350);
			jwin.show();
			jwin.setContentPane(wholePane);

			this.x = 0;
			this.y = 380;
//			添加tab切换时候事件；
			tabbedPane.addStateListener(changeTab);
		}
		
		public function addNewMessage(message:Message):void
		{
			var msgPrefix:String = "[" + Message.TYPE_NAME[message.type] + "]"; 
			switch(message.type)
			{
				case Message.TYPE_NOTICE:
				case Message.TYPE_SYSTEM:
				case Message.TYPE_WORLD:
					textArea.appendText(msgPrefix + message.message + "\n");
				case Message.TYPE_TEAM:
					textArea_1.appendText(msgPrefix + message.message + "\n");
				break;
			}

		}
		public function getMsgType():int
		{
			return tabbedPane.getSelectedIndex();
		}
		
		
		private function changeTab(e:Event):void
		{
			var selIdx:int = e.target.getSelectedIndex()
			if (selComb != null){
				selComb.setSelectedIndex(selIdx);
			}
		}
		
		public function get selectdIdx():int
		{
			return selComb.getSelectedIndex();
		}
		
	}
}